package com.evil.common.rocketmq.enums;

import com.evil.common.core.enums.BaseEnum;
import com.evil.common.core.exception.BusinessException;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.Optional;

/**
 * 企业MQ类型
 *
 * @author liyang
 * @date 2025-03-06 18:23
 */
@Getter
@AllArgsConstructor
public enum EnterpriseMqTypeEnum {

    /**
     * 企业MQ类型
     */
    ENTERPRISE_USER("ENTERPRISE-USER", "企业用户"),
    ENTERPRISE_DEPT("ENTERPRISE-DEPT", "企业部门"),
    ENTERPRISE_ROLE("ENTERPRISE-ROLE", "企业角色"),
    ENTERPRISE_DEPT_USER("ENTERPRISE-DEPT-USER", "企业部门用户"),
    ENTERPRISE_ROLE_USER("ENTERPRISE-ROLE-USER", "企业角色用户"),
    ;
    private final String key;
    private final String title;

    public static Optional<EnterpriseMqTypeEnum> isExistByKey(String key) {
        if (StringUtils.isBlank(key)) {
            return Optional.empty();
        }
        return Arrays.stream(values()).filter(e -> e.key.equals(key)).findFirst();
    }

    public static EnterpriseMqTypeEnum findByKey(String key) {
        return EnterpriseMqTypeEnum.isExistByKey(key).orElseThrow(() ->
                new BusinessException(BaseEnum.ERROR_PARAMETER, "企业MQ操作tag参数错误"));
    }
}
